import { request } from '@inbiz/utils';
import Cookies from 'js-cookie';

export default {
  getUserList(args: any) {
    const data = {
      AllowDept: true,
      AllowPosition: true,
      AllowGroup: true,
      AllowUser: true,
      AllowMyGroup: false,
      AllowMyContact: false,
      type: true,
      HideEveryone: 1,
      SearchContent: args.searchContent || '',
      IsChild: args.isChild || false,
      DeptIds: args.departmentId,
      IsLike: true,
      page: args.pageNum,
      rows: args.pageSize,
    };
    const params = {
      token: Cookies.get('token'),
      index: args.pageNum,
      size: args.pageSize,
      dataFilter: 9,
    };
    return request(`/org/api/UserRead/SearchUserListPaged`, {
      method: 'POST',
      requestType: 'form',
      params,
      data: data,
    });
  },
  getUserGroupList(params?: any) {
    return request(`/org/api/GroupRead/GetGroups`, {
      params: {
        token: Cookies.get('token'),
        dataFilter: 9,
      },
    }).then((res) => {
      if (Array.isArray(res)) {
        return res;
      } else {
        return [];
      }
    });
  },
  getTopPositionList(params) {
    let positionIds = params.positionIds.includes(1) ? [1] : params.positionIds;
    return request(`/org/api/PositionRead/GetPositionInfoByIdentityIds`, {
      params: {
        token: Cookies.get('token'),
        positionIds: positionIds.join(','),
      },
    });
  },
  getSubPositionList(params?: any) {
    return request(`/org/api/PositionRead/GetChildPositionListByIdentityId`, {
      params: {
        token: Cookies.get('token'),
        positionId: params.positionId,
        id: params.id,
      },
    });
  },
  getTopDepartmentList() {
    return request(`/org/api/DeptRead/GetDepartmentInfoByIdentityId`, {
      parmas: {
        token: Cookies.get('token'),
        deptId: 1,
      },
    }).then((res) => {
      if (Array.isArray(res)) {
        return res;
      } else {
        return [];
      }
    });
  },
  getSubDepartmentList(params?: { departId: number; id?: string }) {
    return request(`/org/api/DeptRead/GetChildDepartmentListByIdentityId`, {
      params: {
        token: Cookies.get('token'),
        deptId: params?.departId == null ? 1 : params?.departId,
        id: params?.id,
      },
    }).then((res) => {
      if (Array.isArray(res)) {
        return res;
      } else {
        return [];
      }
    });
  },
};
